package com.kede.controller;

import com.kede.entity.Menu;
import com.kede.entity.User;
import com.kede.service.MenuService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    MenuService menuService;
    @GetMapping({"","/","/index"})
    public String index(Model model){
        List<Menu> rootMenu=menuService.getCurrentMenuListByRoleId();
        //从session获取user对象
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        model.addAttribute("user",user);
        model.addAttribute("rootMenuList",rootMenu);
        return "index";
    }

    @GetMapping("/main")
    public String main(){
        return "main";
    }
    /**
     * 退出
     * @return
     */
    @GetMapping("logout")
    public String logout(){

        Subject subject = SecurityUtils.getSubject();
        subject.logout();

        return "login";
    }

}
